from problembase import ProblemBase
from dolfin import RectangleMesh, Expression,Mesh
from math import sqrt

class RotatedSquare(ProblemBase):
    'Square rotated by velocity field (-y,x). Only side of square can be changed.'
    def __init__(self,options):
        ProblemBase.__init__(self,options)

        self.LL = (-5,-5)
        self.UR = (5,5)
        self.domain = RectangleMesh(self.LL[0],self.LL[1],self.UR[0],self.UR[1],2*self.N,2*self.N)
        
        self.side = 2*sqrt(2)                       # length of the square side
        self.vStrings = ('x[1]','-x[0]')            # string for velocity compononets    
        self.vIsTimeDependent = False               
        self.hasExactSolution = True                # exact is defined
        self.phi_ = self.exact_solution(t=0) 
        self.T = 10    
        self.activeCols = [0,1,2,3,4,5,6,7]
        ProblemBase.register_variables(self)
        self.ibcExpr = self.exact_solution
        self.L = 4*self.side

    def exact_volume(self):
        '''Return problem specific exact volume.'''
        return self.side**2

    def exact_solution(self,t=None):
        '''Return problem specific exact solution at time t.'''
        h = sqrt(self.side**2/2.)
        return Expression('fabs(x[0]*cos(t)-x[1]*sin(t)-2.5)+fabs(x[0]*sin(t)+x[1]*cos(t))-h',h=h,t=t)




